home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14244 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: en.com!usenet
  2. From: dpsm@en.com (Dale P. Smith)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: stl newbie help
  5. Date: Fri, 29 Mar 1996 17:14:49 GMT
  6. Organization: RheoActive
  7. Message-ID: <315c041b.118747@news.en.com>
  8. References: <315ae9a1.455438@news.en.com> <4jevo2$vae@nuacht.iol.ie>
  9. NNTP-Posting-Host: p8-ts4.en.net
  10. X-Newsreader: Forte Agent .99d/16.182
  11.  
  12. David Byrden <Goyra@iol.ie> wrote:
  13. >dpsm@en.com (Dale P. Smith) wrote:
  14. >>What I want to understand how to do is declare a function class that
  15. >>can be used with something like for_each:
  16. >>    for_each(Table.begin(), Table.end(), FunctionClassForEachThing);
  17. >>
  18. >>I know that I have to create a class that has operator() in it. What
  19. >>should this thing look like?  I can't find (or can't see) any examples
  20. >>in the stl documentation.
  21. >>
  22. >
  23. >
  24. >   Dale;
  25. >
  26. >  The various algorithms require different functor signatures; void 
  27. >return, bool return, value return, one parameter, 2 parameters etc. In 
  28. >your example, this signature is required;
  29. >
  30. >
  31. >     void Function( String& ) ;
  32. >
  33. >So, we could use an ordinary function, like the one above;
  34. >
  35. >     void AppendAnE( String& ) ;
  36.  
  37.  
  38. Your example didn't work... but I just figured it out.  The map
  39. container uses pairs.  The signature I needed is:
  40.  
  41.     Function(pair<const key, data>&);
  42.  
  43. This worked:
  44.  
  45. void MyFunc(pair<const int, String>& x)
  46. {
  47.     cout << x.first << ":" << x.second << "\n";
  48. }
  49.  
  50. Thanks! All I needed was a little direction!
  51.  
  52.  
  53. Dale
  54.  
  55.  
  56. Dale P. Smith
  57. dpsm@en.com        home
  58. dpsm@lubrizol.com  work
  59.